***********************
*Time Series Analysis for the Social Sciences
*Box-Steffensmeier, Freeman, Hitt, and Pevehouse
*
*Chapter 2 replication code
************************

************************
*Table 2.1 and Figure 2.1
*Use UCR.dta
*Source: http://www.fbi.gov/about-us/cjis/ucr/ucr
*************************

format mdate %tm
tsset mdate

*Table 2.1

reg homicideth mdate if year > 1984

*Figure 2.1

graph twoway (lfit homicideth mdate if year > 1984) (line homicideth mdate if year > 1984), /// 
xlabel(300(24)396) scheme(s1mono) title(U.S. Homicides 1985-1993 With OLS Trend Line)


*************************
*Figures 2.2 and 2.3
*Use univariate_sims.dta
*Source: simulated
**************************

tsset time

ac white_noise, lags(10)
pac white_noise, lags(10)

ac ar1_7, lags(10)
pac ar1_7, lags(10)

ac ar1_7neg, lags(10)
pac ar1_7neg, lags(10)

ac ar2, lags(10)
pac ar2, lags(10)

ac ma1, lags(10)
pac ma1, lags(10)

ac ma2, lags(10)
pac ma2, lags(10)

ac arma, lags(10)
pac arma, lags(10)

*******************
*Figure 2.4 & Table 2.2
*Use HouseControl.dta
*Source: http://clerk.house.gov/histHigh/Congressional_History/partyDiv.html
*******************

*Figure 2.4
ac prop_dem
pac prop_dem

*Table 2.2

arima prop_dem, arima(1,0,0)

*********************
*Figure 2.5, Table 2.3, & Figure 2.6
*Use UCR.dta
*Source: http://www.fbi.gov/about-us/cjis/ucr/ucr
*********************

*Figure 2.5
ac homicideth
pac homicideth

*Table 2.3
	
	*AR(2)(1,0,12)

arima homicideth, arima(2,0,0) sarima(1,0,0,12)

	*AR(2)(0,1,12)

arima homicideth, arima(2,0,0) sarima(0,0,1,12)

	*AR(3)(1,0,12)

arima homicideth, arima(3,0,0) sarima(1,0,0,12)

	*AR(3)(0,1,12)

arima homicideth, arima(3,0,0) sarima(0,0,1,12)

*Figure 2.6

arima homicideth, arima(2,0,0) sarima(0,0,1,12)

predict homres, resid

ac homres
pac homres

***********************
*Figure 2.7, Table 2.4, Figure 2.8, Table 2.5, & Figure 2.9
*Use Use weisLEV85.dta
*Source: http://web.ku.edu/~keds/data.dir/levant.html
***********************

*Figure 2.7
line ui date || line up date

*Table 2.4

	*AR(1)

arima ui, arima(1,0,0)

	*AR(2)

arima ui, arima(2,0,0)

	*AR(3)

arima ui, arima(3,0,0)

	*MA(1)

arima ui, arima(0,0,1)

	*MA(2)

arima ui, arima(0,0,2)


*Figure 2.8

ac ui, lags(10)
pac ui, lags(10)

ac up, lags(10)
pac up, lags(10)


*Table 2.5

	*AR(1)

arima up, arima(1,0,0)

	*AR(2)

arima up, arima(2,0,0)

	*AR(3)

arima up, arima(3,0,0)

	*MA(1)

arima up, arima(0,0,1)

	*MA(2)

arima up, arima(0,0,2)

	*MA(3)

arima up, arima(0,0,3)

*Figure 2.9

arima ui, arima(2,0,0)
predict uires, resid

ac uires
pac uires

arima up, arima(0,0,3)
predict upres, resid

ac upres
pac upres

*********************
*Figure 2.10
*Use intervention.dta
*********************

line abrupt time 
line pulse time
line gradual time
line decay time


***********************
*Table 2.6
*Use Use weisLEV85.dta
*Source: http://web.ku.edu/~keds/data.dir/levant.html
***********************

	*Abrupt Intervention

arima ui oslo_abrupt, arima(2,0,0)

	*Decay Intervention

arima ui oslo_decay, arima(2,0,0)

	*Pulse Intervention

arima ui oslo_pulse, arima(2,0,0)

	*Gradual Intervention

arima ui oslo_gradual, arima(2,0,0)
